Message Boards Message Boards

0
|
3112 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[Solved] "The first argument is expected to be a string, a valid..."

Posted 4 years ago

First day trying out cloud notebooks.

Unsure why this produces an error:

CloudDeploy[FormFunction[{{"input","Comma Separated Words or Phrases"}->"String"},Sort[WordFrequencyData[{#input}],Greater]]]
POSTED BY: Casey Martell
4 Replies
Posted 4 years ago

Thank you, super helpful.

I'm happy with this for the moment:

CloudDeploy[FormFunction[
{"input" -> <|"Label" -> "Synonyms","Hint" ->"Comma or Pipe Separated Words and Phrases"|>},
Dataset[Sort[WordFrequencyData[StringTrim[StringSplit[#input, {",","|"}]]], Greater]] &,
"Table"]]
POSTED BY: Casey Martell
Posted 4 years ago

Thank you,

I found StringTrim helpful here to:

CloudDeploy[FormFunction[{
"input" -> <|"Label" -> "Synonyms","Hint" ->"Comma or Pipe Separated Words and Phrases"|>
},Sort[WordFrequencyData[StringTrim[StringSplit[#input, {",","|"}]]], Greater] &]]

Is there a 'simple' way to have the output of this appear tabular?

POSTED BY: Casey Martell
Posted 4 years ago

Here are a few ways

WordFrequencyData[{"cat", "dog", "mouse"}] // Dataset

enter image description here

WordFrequencyData[{"cat", "dog", "mouse"}] // 
  KeyValueMap[<|"Word" -> #, "Frequency" -> #2|> &] //
  Dataset

enter image description here

WordFrequencyData[{"cat", "dog", "mouse"}] // 
  KeyValueMap[{#, #2} &] //
  Prepend[Style[#, Bold] & /@ {"Word", "Frequency"}] // 
  Grid[#, Frame -> All, Background -> {None, {Yellow}}] &

enter image description here

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Casey,

There are a couple of problems. A function needs to be passed to FormFunction and the function receives a single string, not a list of strings. Add a & to create a pure function and use StringSplit to generate the list of strings.

FormFunction[{{"input", "Comma Separated Words or Phrases"} -> "String"}, 
 Sort[WordFrequencyData[StringSplit[#input, ","]], Greater] &]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract